<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/>
<title>确认交付订单</title>
<link href="<{$env.app.res_url}>/css/global.css" rel="stylesheet" />
<link href="<{$env.app.res_url}>/css/confirm.css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="<{$env.app.res_url}>/js/moo.js"></script>
</head>
<body>
    <div class="bodyer-header clearfix">
        <div class="top_menu"><a href="<{$delivery_link.dispose}>"><icon></icon><span>进入销单页面</span></a></div>
        <div class="top_logout"><a href="<{$delivery_link.logout}>"><icon></icon><span>退 出</span></a></div>
    </div>
    <div class="bodyer-main">
        <form id="delivery_frm" name="delivery_frm" method="post" action="<{$link_url}>" class="delivery_frm" >
            <div class="link_menus">
                    <{foreach from=$sub_menu item=rs}>
                    <li>
                        <a href="<{$rs.href}>" <{if $rs.curr_view}>class="curr"<{/if}>><{$rs.label}></a>
                    </li>
                    <{/foreach}>
            </div>

            <div class="search-areas">
                <ul class="search-conditions clearfix">
                    <li>
                        <label class="ship_mobile"></label><input name="ship_mobile" type="text" id="ship_mobile" value="收件人手机号" maxlength="11" class="gray" autofocus />
                    </li>
                    <li>
                        <label class="delivery_bn"></label><input type="text" name="delivery_bn" id="delivery_bn" value="发货单号" class="gray" />
                    </li>
                </ul>
                <ul>
                    <li class="search-btn">
                           <button id="btn-search" type="button">
                            <span>
                                <span><{t}>查 询<{/t}></span>
                            </span>
                          </button>
                    </li>
                </ul>
            </div>

            <div class="dly_bills">
                <{if $dataList}>
                    <{foreach from=$dataList item=item}>
                     <div class="delivery_item">
                            <div class="dly_bill clearfix">
                                <icon></icon><span class="dly_bill_no">发货单号：<{$item.delivery_bn}></span><span class="dly_bill_status">状态：<span id="dly_confirm_<{$item.delivery_id}>"><{$item.dly_confirm}></span></span>
                            </div>
                            
                            <div class="ship_name clearfix">
                                <icon></icon>收件人：<{$item.ship_name}>　手机号：<{$item.ship_mobile}>
                            </div>
                            <{if $item.ship_tel}>
                                <div class="ship_tel clearfix">
                                    <icon></icon>电话：<{$item.ship_tel}>
                                </div>
                            <{/if}>
                            <div class="ship_type clearfix"><icon></icon>订单交付方式：<{$item.logi_name}></div>
                            <div class="store_name clearfix"><icon></icon>门店名称：<{$item.shop_info.store_name}></div>
                            <div class="store_mobile clearfix"><icon></icon>门店手机号：<{$item.shop_info.mobile}></div>
                            <{if $item.shop_info.tel}>
                                <div class="store_tel clearfix"><icon></icon>门店电话：<{$item.shop_info.tel}></div>
                            <{/if}>
                            <div class="store_addr clearfix"><icon></icon>门店地址：<{$item.shop_info.area|region}> <{$item.shop_info.addr}></div>
                            <div class="order_bn clearfix">
                                <icon></icon>
                                订单号：<{$item.order_info.order_bn}>
                            </div>
                            <div class="money clearfix">
                                <icon></icon>订单金额：<{$item.order_info.total_amount}>&nbsp;&nbsp;&nbsp;订单类型：<{$item.order_info.is_cod_type}>
                            </div>
                            <div>
                                <{if $baidu_map_show}>
                                <button class="view_map_btn" onclick="show_baidumap_to_store(this)" type="button" store_addr="<{$item.shop_info.addr}>">
                                    <span><span><{t}>查看地图<{/t}></span></span>
                                </button>
                                <{/if}>
                            </div>

                            <div>
                                <{if $item.delivery_items}>
                                <table width="100%" border="0" cellspacing="1" cellpadding="1" style="background:#efefef;">
                                  <tr>
                                    <td bgcolor="#FFFFFF">&nbsp;货 号</td>
                                    <td bgcolor="#FFFFFF">&nbsp;商品名称</td>
                                    <td align="center" bgcolor="#FFFFFF">购买数量</td>
                                  </tr>
                                  <{foreach from=$item.delivery_items item=dly_item}>
                                  <tr>
                                    <td bgcolor="#FFFFFF">&nbsp;<{$dly_item.bn}></td>
                                    <td bgcolor="#FFFFFF">&nbsp;<{$dly_item.product_name}></td>
                                    <td align="center" bgcolor="#FFFFFF"><{$dly_item.number}></td>
                                  </tr>
                                  <{/foreach}>
                                </table>
                                <{/if}>
                            </div>
                        </div>
                        
                        <{if $item.confirm == 3}>
                            <div class="delivery_item_confirm" id="delivery_item_but_<{$item.delivery_id}>">
                                <button id="delivery_confirm_but_<{$item.delivery_id}>" type="button" class="btn confirm-common-btn delivery_confirm_but" onClick="ajax_confirm_delivery('<{$item.delivery_id}>',1)">
                                    <span><span><{t}>门店确认<{/t}></span></span>
                                </button>
                                <button id="delivery_reject_but_<{$item.delivery_id}>" type="button" class="btn confirm-common-btn delivery_confirm_but2" onClick="ajax_confirm_delivery('<{$item.delivery_id}>',2)">
                                    <span><span><{t}>拒绝<{/t}></span></span>
                                </button>
                            </div>
                        <{else}>
                            <div class="delivery_item_confirm">&nbsp;</div>
                        <{/if}>
                    <{/foreach}>
                <{else}>
                    <div class="no_item">暂时没有业务需要处理哦，亲...</div>
                <{/if}>
            </div>

            <div class="page_box">
                <{$page_html}>
            </div>
            <!--
            <div class="bottom_btns clearfix">
                <li class="click_link"><a href="<{$delivery_link.dispose}>">进入销单页面</a></li>
                <li><a href="<{$delivery_link.logout}>">退 出</a></li>
            </div>
            -->
        </form>
    </div>
    <{include file="alert_msg.html"}>

<script type="text/javascript">
(function()
{
    $('delivery_bn').addEvent('focus',function(e)
    {
        if($('delivery_bn').value == "发货单号")
        {
            $('delivery_bn').value = "";
            $('delivery_bn').className = "black";
        }
    });
    $('delivery_bn').addEvent('blur',function(e)
    {
        if($('delivery_bn').value == "")
        {
            $('delivery_bn').value = "发货单号";
            $('delivery_bn').className = "gray";
        }
    });
    $('delivery_bn').addEvent('keypress',function(e)
    {
        if(e.code == 13)
        {
            search_delivery();
        }
    });

    $('ship_mobile').addEvent('click',function(e)
    {
        if($('ship_mobile').value == "收件人手机号")
        {
            $('ship_mobile').value = "";
            $('ship_mobile').className = "black";
        }
    });
    $('ship_mobile').addEvent('blur',function(e)
    {
        if($('ship_mobile').value == "")
        {
            $('ship_mobile').value = "收件人手机号";
            $('ship_mobile').className = "gray";
        }
    });
    $('ship_mobile').addEvent('keypress',function(e)
    {
        if(e.code == 13)
        {
            search_delivery();
        }
        else
        {
            if($('ship_mobile').value == "收件人手机号")
            {
                $('ship_mobile').value = "";
                $('ship_mobile').className = "black";
            }
        }
    });
    
    $('btn-search').addEvent('click', function()
    {
        search_delivery();
    });
    
})();


function show_baidumap_to_store(obj){
    var store_addr = obj.getAttribute("store_addr");
    var position_url = '<{link app=wap ctl=delivery act=showMapByBaidu}>';
    window.open(position_url+"?store_addr="+store_addr);
}

function search_delivery()
{
    var dly_frm = document.delivery_frm;

    ship_mobile    = $("ship_mobile").value;
    delivery_bn    = $("delivery_bn").value;

    if(delivery_bn == "发货单号")
    {
        delivery_bn    = "";
    }

    if(ship_mobile == "收件人手机号")
    {
        ship_mobile    = "";
    }

    if(ship_mobile && !isMobile(ship_mobile))
    {
        alert_msg("手机号填写错误，请检查！");
        return false;
    }

    if(delivery_bn=="" && ship_mobile=="")
    {
        alert_msg("请填写搜索条件！");
        return false;
    }
    $("ship_mobile").value  = ship_mobile;
    $("delivery_bn").value  = delivery_bn;

    dly_frm.submit();
}

function ajax_confirm_delivery(delivery_id,status)
{
    if(delivery_id == "" || status == "")
    {
        alert_msg("无效操作，请检查！");
        return false;
    }

    if(status == 1){
        $('delivery_confirm_but_' + delivery_id).set('disabled', 'true');
    }else{
        $('delivery_reject_but_' + delivery_id).set('disabled', 'true');
    }

    new Request({
        url: "<{$delivery_link.ajaxConfirm}>",
        async:false,
        method:'post',
        data:{delivery_id:delivery_id,status:status},
        onComplete: function(json)
        {
            json = JSON.decode(json);

            var msg = json.msg ? json.msg : '操作失败';
            alert_msg(msg);

            if(json.res == 'succ'){
                if(status == 1){
                    $('delivery_confirm_but_' + delivery_id).set('disabled', '');
                    $("delivery_item_but_" + delivery_id).innerHTML = '<span class="delivery_confirm">已交付订单</span>';
                    $("dly_confirm_" + delivery_id).innerHTML = "已确认";
                }else{
                    $('delivery_reject_but_' + delivery_id).set('disabled', '');
                    $("delivery_item_but_" + delivery_id).innerHTML = '<span class="delivery_confirm">已拒绝订单</span>';
                    $("dly_confirm_" + delivery_id).innerHTML = "已拒绝";
                }
            }
        }
    }).send();
}

function isMobile(mobile)
{
    if(!mobile || mobile.length != 11)
    {
        return false;
    }
    
    var reg    = /^0?1[3|4|5|6|7|8][0-9]\d{8}$/;
    if(reg.test(mobile))
    {
        return true;
    }
    
    return false;
}
</script>
</body>
</html>
